﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Semantics;
public partial class Search : WikiPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack)
            return;
        string url = Request.Url.ToString();
        int pos = url.IndexOf('?');
        if (pos != -1)
        {
            string quest = url.Substring(url.IndexOf('?') + 1);
            IList<Node> results = base.GraphDatabase.QueryNodes(quest);
            this.BannerControl1.SearchText = quest;
            if (results.Count == 0)
            {
                string s = Request.Url.OriginalString;
                s = s.Substring(s.IndexOf('?') + 1);
                this.LabelSearchResults.Text = "查找到0个结果，请尝试查找别的关键字!";
                this.HyperLinkCreateNode.Visible = true;
                this.HyperLinkCreateNode.Text = "创建节点'" + quest + "'";
                this.HyperLinkCreateNode.NavigateUrl = "CreateNode.aspx?" + s;
            }
            else if (results.Count == 1)
            {
                Response.Redirect("WikiNode.aspx?nid=" + results[0].Id);
            }
            else
            {
                this.LabelSearchResults.Text = "找到" + results.Count + "个结果";
                this.Panel1.Controls.Clear();
                NodeListWebControl list = new NodeListWebControl();
                this.Panel1.Controls.Add(list);
                list.Clear();
                list.ShowNodeList(results);
            }
        }
    }
}